package cn.tedu.ivos.geofence.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceParam;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceQueryDTO;
import cn.tedu.ivos.geofence.pojo.vo.GeofenceVO;
import cn.tedu.ivos.geofence.service.GeofenceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
//http://localhost:8080/v1/geofenceselectGeofences
@Slf4j
@RestController
@RequestMapping(value = "/v1/geofence")
public class GeofenceController {
    @Autowired
    GeofenceService geofenceService;

    @GetMapping("/selectGeofences")
    public JsonResult selectGeofences(GeofenceQueryDTO geofenceQueryDTO){
        log.info("控制层处理页面查询'电子围栏'的请求，查询条件->{}",geofenceQueryDTO);
        List<GeofenceVO> geofenceVOList= geofenceService.getGeofenceList(geofenceQueryDTO);
        return JsonResult.ok(geofenceVOList);
    }

    @GetMapping("/select")//本方法和上边的方法一模一样
    public JsonResult selectGeofences2(GeofenceQueryDTO geofenceQueryDTO){
        log.info("控制层处理页面查询'电子围栏'的请求，查询条件->{}",geofenceQueryDTO);
        List<GeofenceVO> geofenceVOList= geofenceService.getGeofenceList(geofenceQueryDTO);
        return JsonResult.ok(geofenceVOList);
    }

    @PostMapping("save")
    public JsonResult saveGeofence(GeofenceParam geofenceParam){
        log.debug("保存围栏信息:geofenceParam={}",geofenceParam);
        geofenceService.saveGeofence(geofenceParam);
        return JsonResult.ok();
    }

    @PostMapping("update/{id}/{status}")//此方法和上边的方法是重复的(一模一样)
    public JsonResult updateGeofence(GeofenceParam geofenceParam){
        log.debug("保存围栏信息:geofenceParam={}",geofenceParam);
        geofenceService.saveGeofence(geofenceParam);
        return JsonResult.ok();
    }

    @PostMapping("delete/{id}")
    public JsonResult deleteGeofence(@PathVariable("id") Long id){
        log.debug("删除围栏:id={}",id);
        geofenceService.deleteGeofence(id);
        return JsonResult.ok();
    }

}
